package com.lebang.medicalInquiry.controller;


import com.lebang.medicalInquiry.constant.ResponseEnum;
import com.lebang.medicalInquiry.model.po.Physician;
import com.lebang.medicalInquiry.model.vo.PageVo;
import com.lebang.medicalInquiry.model.vo.admin.OrganizationListVo;
import com.lebang.medicalInquiry.response.Callback;
import com.lebang.medicalInquiry.response.JsonData;
import com.lebang.medicalInquiry.service.FigureVoiceService;
import com.lebang.medicalInquiry.service.OrganizationService;
import com.lebang.medicalInquiry.service.PhysicianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;


@RequestMapping("/openapi")
@Api(tags = "开放api")
@RestController
@Validated
public class OpenApi {


    @Autowired
    private FigureVoiceService figureVoiceService;

    @Autowired
    private PhysicianService physicianService;

    @Value("${digital.merchant_id}")
    private String merchantId;

    @GetMapping("/generate/voice")
    @ApiOperation("音频生成")
    public JsonData listArticle(HttpServletRequest request, HttpServletResponse response,
                                @ApiParam(name = "content", value = "内容") @NotBlank(message = "文本内容不允许为空") @RequestParam(value = "content", required = false) String content,
                                @ApiParam(name = "voiceId", value = "主播音频id") @NotBlank(message = "voiceId不允许为空") @RequestParam(value = "voiceId", required = false) String voiceId) {


        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), figureVoiceService.getPushTextRoleVoice(content, voiceId));

    }


    @PostMapping("/live/notice")
    @ApiOperation("开播通知")
    public JsonData liveNotice(HttpServletRequest request, HttpServletResponse response,
                               @ApiParam(name = "reason", value = "关播原因") @RequestParam(value = "reason", required = false) String reason,
                               @ApiParam(name = "liveStatus", value = "start,close") @NotBlank(message = "liveStatus 必传") @RequestParam(value = "liveStatus", required = false) String liveStatus,
                               @ApiParam(name = "projectId", value = "项目id必传") @NotBlank(message = "projectId 必传") @RequestParam(value = "projectId", required = false) String projectId) {
        System.out.println("通知:" + projectId+"_"+liveStatus+"_reason:"+reason);
        physicianService.liveNotice(projectId, merchantId,liveStatus);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());

    }
}
